home *** CD-ROM | disk | FTP | other *** search
- #include <osbind.h>
- #include <mintbind.h>
- #include <basepage.h>
- #include <ctype.h>
- #include <minimal.h>
- #include "cookie.h"
- #include "patchlev.h"
- #include "global.h"
- #include "pipe.h"
-
- long _stksize = 65536L;
- int cjar_size = 0;
- COOKIE *new_cjar = 0;
- int ncookies = 0;
- int mint_present = 0;
- int stik_present = 0;
- int pipe_fd = 0;
- #if 0
- Daemon_Interface *DMN = 0;
- #endif
-
- #ifdef __MINT__
- /* We define these here to keep main.o from being pulled out of libc.a */
- int errno;
- int __mint;
- #endif
-
- #if 0
- unsigned long dehexify(register char *buf)
- {
- register unsigned long l = 0;
-
- for (; *buf; buf++)
- l = (l << 4) + toint(*buf);
- return l;
- }
- #endif
-
- int check_cookies(void)
- {
- register COOKIE *cjar = *CJAR, *C;
-
- if (!cjar)
- return 0;
-
- for (C = cjar; C->tag != 0; C++) {
- if (C->tag == COOKIE_MiNT)
- mint_present = 1;
- if (C->tag == COOKIE_STiK)
- stik_present = 1;
- }
-
- cjar_size = C->value;
- ncookies = C - cjar;
- return 0;
- }
-
- int install_same_jar(void)
- {
- register COOKIE *C = *CJAR + ncookies;
-
- C->tag = COOKIE_STiK;
- C->value = (long)&driver;
- C[1].tag = 0;
- C[1].value = cjar_size;
- return 0;
- }
-
- int install_new_jar(void)
- {
- register COOKIE *oldC = *CJAR, *newC = new_cjar;
-
- *CJAR = newC;
- while (oldC->tag != 0)
- *newC++ = *oldC++;
- newC->tag = COOKIE_STiK;
- newC->value = (long)&driver;
- newC[1].tag = 0;
- newC[1].value = cjar_size + 8;
- return 0;
- }
-
- int install_cookie(void)
- {
- if (ncookies < cjar_size - 1)
- return Supexec(install_same_jar);
- else {
- if (!(new_cjar = (COOKIE *)Mxalloc((cjar_size + 8) * sizeof(COOKIE), 3))) {
- Cconws("Unable to install STiK cookie\r\n");
- return -1;
- }
- return Supexec(install_new_jar);
- }
- }
-
- /* cleanup() -- free everything we might have alloced, and destroy all
- semaphores we might have created. */
- static void cleanup(void)
- {
- #if 0 /* The daemon will destroy these */
- /* We have to be holding the semaphore to destroy it */
- Psemaphore(2, DMN_SEMAPHORE, -1L);
- Psemaphore(1, DMN_SEMAPHORE, 0L);
- #ifdef DEBUG
- Psemaphore(2, DEBUG_SEMAPHORE, -1L);
- Psemaphore(1, DEBUG_SEMAPHORE, 0L);
- #endif /* DEBUG */
- #endif /* 0 */
- }
-
- int main()
- {
- Cconws("\r\nGlueSTiK\277 STiK emulator for MiNTnet\r\n"
- "Application interface driver\r\n"
- "Version " GS_VERSION "\r\n"
- "\275 1996 Scott Bigham\r\n");
- #ifdef DEBUG
- Cconws(" Debug logging enabled\r\n");
- #endif
- #ifdef DEBUG
- debug("s", "Starting GSDriver v" GS_VERSION);
- #endif
-
- #if 0
- if (argc != 2) {
- Cconws("Daemon address absent --- not installing\r\n");
- return -1;
- }
- DMN = (Daemon_Interface *)dehexify(argv[1]);
- #ifdef DEBUG
- debug("sssX", "Ifc ptr = ", argv[1], ", magic = ", (DMN ? DMN->magic : 0L));
- #endif
- if (!DMN || (DMN->magic != GSDAEMON_MAGIC)) {
- Cconws("Daemon address invalid --- not installing\r\n");
- return -1;
- }
- #endif /* 0 */
-
- Supexec(check_cookies);
- if (!mint_present) {
- Cconws("MiNT not present --- not installing\r\n");
- return -1;
- }
- if (stik_present) {
- Cconws("STiK already present --- not installing\r\n");
- return 0;
- }
-
- if (!init_stubs()) {
- cleanup();
- return -1;
- }
- #ifdef DEBUG
- debug("s", "Network stub functions initialized");
- #endif
-
- if (install_cookie() < 0) {
- cleanup();
- return -1;
- }
- #ifdef DEBUG
- debug("s", "STiK cookie installed");
- #endif
-
- Cconws("\r\n");
- Ptermres(1024L + _base->p_tlen + _base->p_dlen + _base->p_blen, 0);
- return -1;
- }
-